package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.SmallVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {

    @Autowired
    private SmallVideosService smallVideosService;


    /**
     * 发布视频功能
     *    请求方式：POST
     *    请求参数：
     *      videoThumbnail：封面图片
     *      videoFile：视频文件
     *    不需要返回值：null
     */
    @PostMapping
    public ResponseEntity smallVideos(MultipartFile videoThumbnail,MultipartFile videoFile)
            throws IOException {
        smallVideosService.saveVideos(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询视频列表
     *    请求方式：GET
     *    请求参数（Query）：
     *      page,pagesize
     *    返回值：
     *      PageResult -- List<VideoVo>
     */
    @GetMapping
    public ResponseEntity findVideos(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize) {
        //调用service
        PageResult vo = smallVideosService.findVideos(page,pagesize);
        return ResponseEntity.ok(vo);
    }

    /**
     * 模拟视频点赞：为了发送评分消息
     */
    @PostMapping("{videoId}/like")
    public ResponseEntity like(@PathVariable("videoId") String videoId) {
        smallVideosService.like(videoId);
        return ResponseEntity.ok(null);
    }
}
